$(document).ready(function () {
        	//加载单位数据
        	loadCompanyList();
        	
        	$("#editDepartmentForm input[name='close']").click(function () {
       		    $("#editDataFormArea").window("close");
       	    })
        	
        	//当改变选项后给companyName赋值
        	$("#editDepartmentForm select[name='companyUUID']").change(function(){
        	    var companyName= $("#editDepartmentForm select[name='companyUUID'] option:selected").text();
        	    $("#editDepartmentForm input[name='companyName']").val(companyName)
        	})
        	
        	var id = new Number($("#editDepartmentForm  input[name='id']").val());
        	var rules = {}
        	var messages = {}
        	messages = {
        	   companyUUID:"请选择所属公司",
        	   departmentName:"请输入部门名字"
            };
        	
        	var validateForm = $("#editDepartmentForm #dataForm").validate({
                debug:true,
                rules:rules,
                messages:messages
            });
        	
            //提交数据到服务器
            $("#editDepartmentForm input[name='submitData']").click(function () {
            	//提交表单进行验证
            	$("#editDepartmentForm #dataForm").submit();
                var validateFlag = validateForm.form();
                var actionUrl = $("#editDepartmentForm #dataForm").attr("action");
            	var formData  = $("#editDepartmentForm #dataForm").form2Json();
            	if(validateFlag){
            		$("#editDepartmentForm #dataForm").form('submit',{
            			//当提交时
            			onSubmit:function(param){
            			},
            			success:function(data){
            				var data = eval('(' + data + ')');
            				if(data.code=="00"){
              				  $.messager.confirm('操作确认',data.msg+',请确认是否继续操作？',function(flag){
              					  if(flag){
              						  $("#editDataFormArea").window("close");
              						  tableObject.datagrid('reload');
              					  }
              				  });
              			    }else{
              				   $.messager.alert('操作提示',data.message,'error');
              			    }
            			}
            		});
            	}
            });
            
        	if(id>0){
        		//加载表单数据
            	loadFormData(id+"");
        	}
        });
        
        //通过表单加载数据
        function loadFormData(id){
        	$.post(getBasePath()+"/department/getJsonDetail.do",{id:id},function(jsonData){
        		$("#editDepartmentForm #dataForm").form("load",jsonData.data);
        		console.log("companyUUID",companyUUID);
        		$("#companyUUID").attr("curv",jsonData.data.companyUUID);
  		    },"json");
        }
        
        //加载单位数据
        function loadCompanyList(){
        	$.post(getBasePath()+"company/getJsonAllList.do",{},function(jsonData){
        		var optionList = "<option value=\"\">请选择</option>";
        		var selectArea = $("#editDepartmentForm select[name='companyUUID']");
        		var curUUID = selectArea.attr("curv");
        		$.each(jsonData.data,function(i,item){
        			if(item.uuid==curUUID){
        				optionList+= "<option value=\""+item.uuid+"\" selected>"+item.companyName+"</option>";
        				$("#editDepartmentForm input[name='companyName']").val(item.companyName)
        			}else{
        				optionList+= "<option value=\""+item.uuid+"\">"+item.companyName+"</option>";
        			}
        		})
        		selectArea.html(optionList);
  		    },"json");
        }